package com.yang.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;
    private String message;
    private T data;

    public static <R> ResponseResult<R> success(R data) {
        return new ResponseResult<>(200, "调用成功", data);
    }

    public static <R> ResponseResult<R> success() {
        return new ResponseResult<>(200, "调用成功", null);
    }

    public static <R> ResponseResult<R> fail(String message) {
        return new ResponseResult<>(400, message, null);
    }

    public static <R> ResponseResult<R> fail(int code, String message) {
        return new ResponseResult<>(code, message, null);
    }

    public ResponseResult() {
    }

    public ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

}
